package com.store.app.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hyphenate.easeui.widget.CircleImageView;
import com.store.app.R;
import com.store.app.bean.GroupBean;
import com.store.app.utils.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * Created by Administrator on 2016/8/26.
 */
public class GroupListAdapter extends BaseAdapter {
    private List<GroupBean> groupBeanList;
    private Context context;
    public GroupListAdapter(Context context, List<GroupBean> groupBeanList){
        this.context = context;
        this.groupBeanList = groupBeanList;
    }
    @Override
    public int getCount() {
        return groupBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return groupBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView =  LayoutInflater.from(context).inflate(R.layout.item_group,null);
            viewHolder.tvGroupName = (TextView) convertView.findViewById(R.id.name);
            viewHolder.circleImageView = (CircleImageView) convertView.findViewById(R.id.avatar);
            viewHolder.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(viewHolder);			//表示给View添加一个格外的数据，
        } else {
            viewHolder = (ViewHolder)convertView.getTag();//通过getTag的方法将数据取出来
        }
        viewHolder.tvGroupName.setText(groupBeanList.get(position).getName());
//        try {
//            String data = "";
//            long l = (Long.parseLong(groupBeanList.get(position).getCreated()));
//            viewHolder.tvTime.setText(DateUtil.date2Str(new Date(l), DateUtil.fmt_yyyyMMddHHmmss));
//        }catch (Exception e){}
        return convertView;
    }
    class ViewHolder{
        TextView tvGroupName;//群名称
        CircleImageView circleImageView;//群头像
        TextView tvTime;//时间
    }
}
